#include <iostream>
using namespace std;

class singleton{
    private:
        static singleton *instance;
        singleton(){}
    public:
        static singleton& getInstance(){
            if(instance == nullptr){
                instance = new singleton();
            }
            return *instance;
        }
        void hello(){
            cout<<"hello"<<endl;
        }
};
singleton *singleton::instance = nullptr;//静态成员初始化

class singleton_lazy{
    private:
        singleton_lazy(){}
        singleton_lazy(const singleton_lazy&) = delete;//禁止拷贝
        singleton_lazy& operator=(const singleton_lazy&) = delete;//禁止赋值
    public:
        ~singleton_lazy(){}
        static singleton_lazy& getInstance(){
            static singleton_lazy instance;//静态实例对象，只初始化一次，生命周期内始终存在
            return instance;
        }
        void hello(){
            cout<<"hello"<<endl;
        }
};

int main(int argc, char const *argv[])
{
    singleton::getInstance()->hello();//唯一实例访问点singleton::getInstance()
    singleton_lazy& sl = singleton_lazy::getInstance();
    sl.hello();
}
